package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_ZhiWei_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.ZhaoPing;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ZhaoPing_Adapter extends BaseAdapter {
    private Context context;
    private ArrayList<ZhaoPing> list;


    public ZhaoPing_Adapter(Context context, ArrayList<ZhaoPing> list) {
        super();
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int arg0) {
        return arg0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(context, R.layout.zhaoping_item, null);
            mHolder.textview_zhaoping_title = (TextView) convertView.findViewById(R.id.textview_zhaoping_title);
            mHolder.textview_gongsi_name = (TextView) convertView.findViewById(R.id.textview_gongsi_name);
            mHolder.textview_place_xueli = (TextView) convertView.findViewById(R.id.textview_place_xueli);
            mHolder.zhaoping_time = (TextView) convertView.findViewById(R.id.zhaoping_time);
            mHolder.zhaoping_xinzi = (TextView) convertView.findViewById(R.id.zhaoping_xinzi);
            convertView.setTag(mHolder);
        }
        mHolder = (Holder) convertView.getTag();
        mHolder.textview_zhaoping_title.setText(list.get(position).getJob_title());
        mHolder.textview_gongsi_name.setText(list.get(position).getCom_name());
        mHolder.zhaoping_time.setText(list.get(position).getCreated_at().substring(0, 10));
        if (list.get(position).getJob_education() == 1) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 初中");
        } else if (list.get(position).getJob_education() == 2) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 中技");
        } else if (list.get(position).getJob_education() == 3) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 高中");
        } else if (list.get(position).getJob_education() == 4) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 中专");
        } else if (list.get(position).getJob_education() == 5) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 大专");
        } else if (list.get(position).getJob_education() == 6) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 本科");
        } else if (list.get(position).getJob_education() == 7) {
            mHolder.textview_place_xueli.setText(list.get(position).getPrivonce() + "  " + list.get(position).getCity() + "  |" + " 硕士");
        }
        if (list.get(position).getJob_salary() == 1) {
            mHolder.zhaoping_xinzi.setText("1000-2000 元/月");
        } else if (list.get(position).getJob_salary() == 2) {
            mHolder.zhaoping_xinzi.setText("2001-4000 元/月");
        } else if (list.get(position).getJob_salary() == 3) {
            mHolder.zhaoping_xinzi.setText("4001-6000 元/月");
        } else if (list.get(position).getJob_salary() == 4) {
            mHolder.zhaoping_xinzi.setText("6001-8000 元/月");
        } else if (list.get(position).getJob_salary() == 5) {
            mHolder.zhaoping_xinzi.setText("8001-10000 元/月");
        } else if (list.get(position).getJob_salary() == 6) {
            mHolder.zhaoping_xinzi.setText("10001-15000 元/月");
        } else if (list.get(position).getJob_salary() == 7) {
            mHolder.zhaoping_xinzi.setText("15000-25000 元/月");
        } else if (list.get(position).getJob_salary() == 8) {
            mHolder.zhaoping_xinzi.setText("25000 以上");
        } else if (list.get(position).getJob_salary() == 9) {
            mHolder.zhaoping_xinzi.setText("面议");
        }
        final int a = position;
        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, Main_ZhiWei_DetailsActivity.class);
                intent.putExtra("zhiwei_id", list.get(a).getId());

                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class Holder {

        TextView textview_zhaoping_title;
        TextView textview_gongsi_name;
        TextView textview_place_xueli;
        TextView zhaoping_time;
        TextView zhaoping_xinzi;
    }

}
